package com.cn.my.newapp

import android.content.Context
import android.content.res.AssetManager
import android.content.res.Resources
import android.graphics.drawable.Drawable

object SkinManager {
    private var skinResources: Resources? = null

    fun loadSkin(context: Context, apkPath: String) {
        val assetManager = AssetManager::class.java.newInstance()
        val addAssetPathMethod = assetManager.javaClass.getMethod("addAssetPath", String::class.java)
        addAssetPathMethod.invoke(assetManager, apkPath)

        val superRes = context.resources
        skinResources = Resources(assetManager, superRes.displayMetrics, superRes.configuration)
    }

    fun getDrawable(resId: Int): Drawable? {
        return skinResources?.getDrawable(resId)
    }
}